#pragma warning(disable:4005)
#include <drogon/HttpController.h>
#include "OCServer/DocGenerate.h"
#include "MyProject.h"

using namespace drogon;
using namespace OCPP;

class WeathertoyServcie : public HttpController<WeathertoyServcie>
{
public:
	METHOD_LIST_BEGIN
		METHOD_ADD(WeathertoyServcie::home, "", Get);
		METHOD_ADD(WeathertoyServcie::newProject, "newProject", Post);
		METHOD_ADD(WeathertoyServcie::openProject, "openProject", Post);
		METHOD_ADD(WeathertoyServcie::closeProject, "closeProject", Get);
		METHOD_ADD(WeathertoyServcie::getProjectData, "getProjectData", Post);
		METHOD_ADD(WeathertoyServcie::createProject, "createProject", Post);
		METHOD_ADD(WeathertoyServcie::updateProject, "updateProject", Post);
		METHOD_ADD(WeathertoyServcie::listProject, "listProject", Get);
		METHOD_ADD(WeathertoyServcie::importData1, "importData1", Post);
		METHOD_ADD(WeathertoyServcie::importData2, "importData2", Post);
		METHOD_ADD(WeathertoyServcie::listTime, "listTime?type={type}", Get);
		METHOD_ADD(WeathertoyServcie::getGeoObservetData, "getGeoObservetData?time={time}", Get);
		METHOD_ADD(WeathertoyServcie::updateData1, "updateData1", Post);
		METHOD_ADD(WeathertoyServcie::deleteData1, "deleteData1", Post);

		METHOD_LIST_END
protected:
	void home(const HttpRequestPtr& req,
		std::function<void(const HttpResponsePtr&)>&& callback)
	{
		auto resp = HttpResponse::newHttpResponse();
		resp->setBody("WeathertoyServcie");
		callback(resp);
	}

	void newProject(const HttpRequestPtr& req,
		std::function<void(const HttpResponsePtr&)>&& callback)
	{
		auto resp = HttpResponse::newHttpResponse();
		String data = Singleton(MyProject).newProject(req->getBody().data());
		resp->setBody(data);
		callback(resp);
	}

	void openProject(const HttpRequestPtr& req,
		std::function<void(const HttpResponsePtr&)>&& callback)
	{
		auto resp = HttpResponse::newHttpResponse();
		String data = Singleton(MyProject).openProject(req->getBody().data());
		resp->setBody(data);
		callback(resp);
	}

	void closeProject(const HttpRequestPtr& req,
		std::function<void(const HttpResponsePtr&)>&& callback)
	{
		auto resp = HttpResponse::newHttpResponse();
		Singleton(MyProject).closeProject();
		resp->setBody("true");
		callback(resp);
	}
	
	void getProjectData(const HttpRequestPtr& req,
		std::function<void(const HttpResponsePtr&)>&& callback)
	{
		auto resp = HttpResponse::newHttpResponse();
		String data = Singleton(MyProject).getProjectData(req->getBody().data());
		resp->setBody(data);
		callback(resp);
	}

	void createProject(const HttpRequestPtr& req,
		std::function<void(const HttpResponsePtr&)>&& callback)
	{
		auto resp = HttpResponse::newHttpResponse();
		String data = Singleton(MyProject).createProject(req->getBody().data());
		resp->setBody(data);
		callback(resp);
	}

	void updateProject(const HttpRequestPtr& req,
		std::function<void(const HttpResponsePtr&)>&& callback)
	{
		auto resp = HttpResponse::newHttpResponse();
		String data = Singleton(MyProject).updateProject(req->getBody().data());
		resp->setBody(data);
		callback(resp);
	}

	void listProject(const HttpRequestPtr& req,
		std::function<void(const HttpResponsePtr&)>&& callback)
	{
		auto resp = HttpResponse::newHttpResponse();
		String data = Singleton(MyProject).listProject();
		resp->setBody(data);
		callback(resp);
	}

	void listTime(const HttpRequestPtr& req,
		std::function<void(const HttpResponsePtr&)>&& callback,String type)
	{
		auto resp = HttpResponse::newHttpResponse();
		String data = Singleton(MyProject).listTime(type);
		resp->setBody(data);
		callback(resp);
	}

	void importData1(const HttpRequestPtr& req,
		std::function<void(const HttpResponsePtr&)>&& callback)
	{
		auto resp = HttpResponse::newHttpResponse();
		String data = Singleton(MyProject).importData1(req->getBody().data());
		resp->setBody(data);
		callback(resp);
	}
	
	void importData2(const HttpRequestPtr& req,
			std::function<void(const HttpResponsePtr&)>&& callback)
	{
		auto resp = HttpResponse::newHttpResponse();
		String data = Singleton(MyProject).importData2(req->getBody().data());
		resp->setBody(data);
		callback(resp);
	}
	void getGeoObservetData(const HttpRequestPtr& req,
		std::function<void(const HttpResponsePtr&)>&& callback, String time)
	{
		auto resp = HttpResponse::newHttpResponse();
		String data = Singleton(MyProject).getGeoObserveData(time);
		resp->setBody(data);
		callback(resp);
	}
	void updateData1(const HttpRequestPtr& req,
		std::function<void(const HttpResponsePtr&)>&& callback)
	{
		auto resp = HttpResponse::newHttpResponse();
		String data = Singleton(MyProject).updateData1(req->getBody().data());
		resp->setBody(data);
		callback(resp);
	}
	void deleteData1(const HttpRequestPtr& req,
		std::function<void(const HttpResponsePtr&)>&& callback)
	{
		auto resp = HttpResponse::newHttpResponse();
		String data = Singleton(MyProject).deleteData1(req->getBody().data());
		resp->setBody(data);
		callback(resp);
	}
};